package cn.com.sd.system.dao.hibernate;

import java.util.List;

import org.springframework.stereotype.Component;

import cn.com.sd.common.util.MyStringUtils;
import cn.com.sd.common.util.Page;
import cn.com.sd.system.dao.IOrganizationDAO;
import cn.com.sd.system.model.Organization;

@SuppressWarnings("unchecked")
@Component(value = "organizationDAO")
public class OrganizationDAOHibernate extends BaseDAOHibernate<Organization> implements IOrganizationDAO{

	@Override
	public Organization detail(Integer id) {
		String hql = "from Organization org left join fetch org.operators where org.id=?";
		Organization org = (Organization) findUnique(hql, id);
		return org;
	}
	
	@Override
	public List<Organization> getOrganizationList(Page page) {
		List<Organization> organizations = createQuery("from Organization").setFirstResult(page.getStartRow()).setMaxResults(page.getStartRow() + page.getPageSize()).list();
		return organizations;
	}
	
	@Override
	public Integer getOrganizationCount() {
		String hql = "select count(organization.id) from Organization organization";
		Long count = (Long) findUnique(hql);
		return MyStringUtils.translateLongToInteger(count);
	}
}
